package command.usuario;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;

import model.Pasta;

import command.ICommand;

import dao.assinatura.CasoDAO;
import dao.assinatura.PastaDAO;
import dao.fabrica.FabricaDAO;

public class EditarPastaCommand implements ICommand{
	
	private String obs;
	private String pastaId;
	
	public String execute(HttpServletRequest request) throws ServletException, IOException {
			
			try {
				 obs = request.getParameter("inputObs");
				 pastaId = request.getParameter("p");
				 if (obs != null && pastaId != null)
				 {
					 PastaDAO pastaDAO = FabricaDAO.createPasta();
					 Pasta pasta = pastaDAO.getPastaById(Integer.parseInt(pastaId));
					 pasta.setObs(obs);
					 pastaDAO.updatePasta(pasta);
					 
				 }else
					 return "/paginas/editar/pasta.jsp?p="+pastaId;
				 
				 
			} catch (SQLException e) {
				e.printStackTrace();
				return "/paginas/cadastro_invalido.jsp";
			}
			
			return "/paginas/visualizar/pasta.jsp?resultado=OK&p="+pastaId;
		}
}
